package com.william.lifetraxer.util;

import static com.william.lifetraxer.util.DbManager.dbUserTable;
import static com.william.lifetraxer.util.DbManager.getUser;
import static com.william.lifetraxer.util.DbManager.getUsers;
import static com.william.lifetraxer.util.DbManager.insertUser;
import static com.william.lifetraxer.util.DbManager.resetPassword;

import java.util.List;
public class UserDAO {
	
	public static int insert(User user)
	{
		String insertString = "insert into " + dbUserTable +" (username,password) value(?,?)";
		return insertUser(insertString,user);
	}
	
	public static int reset(User user , String newPassword)
	{
		String updateString = "update " + dbUserTable + " set password = ? where userid = ? ";
		return resetPassword(updateString , user , newPassword);
	}
	
	public static User get(int userid)
	{
		String queryString = "select username from " + dbUserTable + " where userid = ? ";
		return getUser(queryString,userid);
	}
	
	public static List<User> getOnlineUser()
	{
		String queryString = "select username from " + dbUserTable + " where statu = ? ";
		return getUsers(queryString,1);
	}
	
	public static void main(String[] args)
	{
		insert(new User("william","12312"));
	}
}
